package com.cs171.market.Aspect;


import com.cs171.market.service.CheckUserService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class CheckUserAspect {
    //AOP：面向切面编程，进行权限控制的切面

    @Autowired
    private CheckUserService checkUserService;

    // 对该包下的所有类的所有方法的所有参数，作为切面：可以是注解或表达式
//    @Pointcut("execution(* com.cs171.market.service.*.*(..))")
//    public void checkAdmin(){
//
//    }

    //在执行方法前先做checkAdmin()，Before前置控制，参数为连接点：增强了哪些方法
//    @Before("checkAdmin()")
//    public void before(JoinPoint joinPoint) throws Exception {
//        System.out.println("--------------【前置通知】----------"+joinPoint);
//        //checkUserService.check();
//    }
//
//    @After("checkAdmin()")
//    public void after(JoinPoint joinPoint) throws Exception {
//        System.out.println("--------------【后置通知】----------"+joinPoint);
//        //checkUserService.check();
//    }
//
//    @AfterReturning(value = "checkAdmin()", returning = "userId")
//    public void afterReturning(Object userId) throws Exception {
//        System.out.println("--------------【返回后置通知】----------"+userId);
//        //checkUserService.check();
//    }
//
//    @AfterThrowing(value="checkAdmin()", throwing = "e")
//    public void afterThrowing(Throwable e) throws Exception {
//        System.out.println("--------------【异常后置通知】----------"+e.getMessage());
//        //checkUserService.check();
//    }
//
//    //@Around 环绕通知
//    @Around(value = "checkAdmin()")
//    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
//        System.out.println("--------------【环绕通知前】----------");
//        Object obj = joinPoint.proceed(); //执行目标方法
//        System.out.println("--------------【环绕通知后】----------");
//        return obj;
//    }

}
